home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / POVSRC / SOURCE / FRAME.H < prev    next >
Text File  |  1994-02-03  |  27KB  |  1,073 lines

  1. /****************************************************************************
  2. *                   frame.h
  3. *
  4. *  This header file is included by all C modules in POV-Ray. It defines all
  5. *  globally-accessible types and constants.
  6. *
  7. *  from Persistence of Vision Raytracer
  8. *  Copyright 1993 Persistence of Vision Team
  9. *---------------------------------------------------------------------------
  10. *  NOTICE: This source code file is provided so that users may experiment
  11. *  with enhancements to POV-Ray and to port the software to platforms other 
  12. *  than those supported by the POV-Ray Team.  There are strict rules under
  13. *  which you are permitted to use this file.  The rules are in the file
  14. *  named POVLEGAL.DOC which should be distributed with this file. If 
  15. *  POVLEGAL.DOC is not available or for more info please contact the POV-Ray
  16. *  Team Coordinator by leaving a message in CompuServe's Graphics Developer's
  17. *  Forum.  The latest version of POV-Ray may be found there as well.
  18. *
  19. * This program is based on the popular DKB raytracer version 2.12.
  20. * DKBTrace was originally written by David K. Buck.
  21. * DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
  22. *
  23. *****************************************************************************/
  24.  
  25. /* Generic header for all modules */
  26.  
  27. #include <math.h>
  28. #include <stdio.h>
  29. #include <string.h>
  30. #include <limits.h>
  31. #include "config.h"
  32.  
  33.  
  34. /* These are used by POVRAY.C and the machine specific modules */
  35.  
  36. #define POV_RAY_VERSION "2.2"
  37.  
  38. /* This message is for the personal distribution release. */
  39. #define DISTRIBUTION_MESSAGE_1 "This is an unofficial version compiled by:"
  40. #define DISTRIBUTION_MESSAGE_2 "FILL IN NAME HERE........................."
  41. #define DISTRIBUTION_MESSAGE_3 "The POV-Ray Team is not responsible for supporting this version."
  42.  
  43. #ifndef READ_ENV_VAR_BEFORE 
  44. #define READ_ENV_VAR_BEFORE 
  45. #endif
  46. #ifndef READ_ENV_VAR_AFTER
  47. #define READ_ENV_VAR_AFTER if ((Option_String_Ptr = getenv("POVRAYOPT")) != NULL) read_options(Option_String_Ptr);   
  48. #endif
  49.  
  50. #ifndef CONFIG_MATH
  51. #define CONFIG_MATH
  52. #endif
  53.  
  54. #ifndef EPSILON
  55. #define EPSILON 1.0e-10
  56. #endif
  57.  
  58. #ifndef FILE_NAME_LENGTH
  59. #define FILE_NAME_LENGTH 150
  60. #endif
  61.  
  62. #ifndef HUGE_VAL
  63. #define HUGE_VAL 1.0e+17
  64. #endif
  65.  
  66. #ifndef BOUND_HUGE
  67. #define BOUND_HUGE 1.0e30
  68. #endif
  69.  
  70. #ifndef DBL_FORMAT_STRING
  71. #define DBL_FORMAT_STRING "%lf"
  72. #endif
  73.  
  74. #ifndef DEFAULT_OUTPUT_FORMAT
  75. #define DEFAULT_OUTPUT_FORMAT    'd'
  76. #endif
  77.  
  78. #ifndef RED_RAW_FILE_EXTENSION
  79. #define RED_RAW_FILE_EXTENSION ".red"
  80. #endif
  81.  
  82. #ifndef GREEN_RAW_FILE_EXTENSION
  83. #define GREEN_RAW_FILE_EXTENSION ".grn"
  84. #endif
  85.  
  86. #ifndef BLUE_RAW_FILE_EXTENSION
  87. #define BLUE_RAW_FILE_EXTENSION ".blu"
  88. #endif
  89.  
  90. #ifndef FILENAME_SEPARATOR
  91. #define FILENAME_SEPARATOR "/"
  92. #endif
  93.  
  94. /* 0==yes 1==no 2==opt */
  95. #ifndef CASE_SENSITIVE_DEFAULT
  96. #define CASE_SENSITIVE_DEFAULT 0
  97. #endif
  98.  
  99. #ifndef READ_FILE_STRING
  100. #define READ_FILE_STRING "rb"
  101. #endif
  102.  
  103. #ifndef WRITE_FILE_STRING
  104. #define WRITE_FILE_STRING "wb"
  105. #endif
  106.  
  107. #ifndef APPEND_FILE_STRING
  108. #define APPEND_FILE_STRING "ab"
  109. #endif
  110.  
  111. #ifndef NORMAL
  112. #define NORMAL '0'
  113. #endif
  114.  
  115. #ifndef GREY
  116. #define GREY   'G'
  117. #endif
  118.  
  119. #ifndef START_TIME
  120. #define START_TIME time(&tstart);     
  121. #endif
  122.  
  123. #ifndef STOP_TIME
  124. #define STOP_TIME  time(&tstop);
  125. #endif
  126.  
  127. #ifndef TIME_ELAPSED
  128. #define TIME_ELAPSED difftime (tstop, tstart);
  129. #endif
  130.  
  131. #ifndef STARTUP_POVRAY
  132. #define STARTUP_POVRAY
  133. #endif
  134.  
  135. #ifndef PRINT_OTHER_CREDITS
  136. #define PRINT_OTHER_CREDITS
  137. #endif
  138.  
  139. #ifndef TEST_ABORT
  140. #define TEST_ABORT
  141. #endif
  142.  
  143. #ifndef FINISH_POVRAY
  144. #define FINISH_POVRAY
  145. #endif
  146.  
  147. #ifndef COOPERATE
  148. #define COOPERATE 
  149. #endif
  150.  
  151. #ifndef DBL
  152. #define DBL double
  153. #endif
  154.  
  155. #ifndef ACOS
  156. #define ACOS acos
  157. #endif
  158.  
  159. #ifndef SQRT
  160. #define SQRT sqrt
  161. #endif
  162.  
  163. #ifndef POW
  164. #define POW pow
  165. #endif
  166.  
  167. #ifndef COS
  168. #define COS cos
  169. #endif
  170.  
  171. #ifndef SIN
  172. #define SIN sin
  173. #endif
  174.  
  175. #ifndef labs
  176. #define labs(x) (long) ((x<0)?-x:x)
  177. #endif
  178.  
  179. #ifndef max
  180. #define max(x,y) ((x<y)?y:x)
  181. #endif
  182.  
  183. #ifndef STRLN
  184. #define STRLN(x) x
  185. #endif
  186.  
  187. #ifndef PARAMS
  188. #define PARAMS(x) x
  189. #endif
  190.  
  191. #ifndef ANSIFUNC
  192. #define ANSIFUNC 1
  193. #endif
  194.  
  195. #ifndef M_PI
  196. #define M_PI 3.1415926535897932384626
  197. #endif
  198.  
  199. #ifndef TRUE
  200. #define TRUE 1
  201. #define FALSE 0
  202. #endif
  203.  
  204. #ifndef IFF_SWITCH_CAST
  205. #define IFF_SWITCH_CAST (int)
  206. #endif
  207.  
  208. #ifndef PRINT_CREDITS
  209. #define PRINT_CREDITS print_credits();
  210. #endif
  211.  
  212. #ifndef PRINT_STATS
  213. #define PRINT_STATS print_stats();
  214. #endif
  215.  
  216. #ifndef MAX_CONSTANTS
  217. #define MAX_CONSTANTS 1000
  218. #endif
  219.  
  220. #ifndef WAIT_FOR_KEYPRESS
  221. #define WAIT_FOR_KEYPRESS
  222. #endif
  223.  
  224. #ifndef CDECL
  225. #define CDECL
  226. #endif
  227.  
  228. #ifndef MAX_BUFSIZE
  229. #define MAX_BUFSIZE INT_MAX
  230. #endif
  231.  
  232. /* If compiler version is undefined, then make it 'u' for unknown */
  233. #ifndef COMPILER_VER
  234. #define COMPILER_VER ".u"
  235. #endif
  236.  
  237. #ifndef QSORT_FUNCT_RET
  238. #define QSORT_FUNCT_RET int CDECL
  239. #endif
  240.  
  241. #ifndef QSORT_FUNCT_PARAM
  242. #define QSORT_FUNCT_PARAM void *
  243. #endif
  244.  
  245. #ifndef MAIN_RETURN_TYPE
  246. #define MAIN_RETURN_TYPE void
  247. #endif
  248.  
  249. #ifndef MAIN_RETURN_STATEMENT
  250. #define MAIN_RETURN_STATEMENT
  251. #endif
  252.  
  253. /* These values determine the minumum and maximum distances
  254.    that qualify as ray-object intersections */
  255. #define Small_Tolerance 0.001
  256. #define Max_Distance 1.0e7
  257.  
  258. typedef struct istk_entry INTERSECTION;
  259. typedef struct Vector_Struct VECTOR;
  260. typedef DBL MATRIX [4][4];
  261. typedef struct Bounding_Box_Struct BBOX;
  262. typedef struct Colour_Struct COLOUR;
  263. typedef struct Colour_Map_Entry COLOUR_MAP_ENTRY;
  264. typedef struct Colour_Map_Struct COLOUR_MAP;
  265. typedef struct Transform_Struct TRANSFORM;
  266. typedef struct Image_Struct IMAGE;
  267. typedef struct Texture_Struct TEXTURE;
  268. typedef struct Material_Texture_Struct MATERIAL;
  269. typedef struct Tiles_Texture_Struct TILES;
  270. typedef struct Pattern_Struct TPATTERN;
  271. typedef struct Pigment_Struct PIGMENT;
  272. typedef struct Tnormal_Struct TNORMAL;
  273. typedef struct Finish_Struct FINISH;
  274. typedef struct Method_Struct METHODS;
  275. typedef struct Camera_Struct CAMERA;
  276. typedef struct Object_Struct OBJECT;
  277. typedef struct Composite_Struct COMPOSITE;
  278. typedef struct Sphere_Struct SPHERE;
  279. typedef struct Quadric_Struct QUADRIC;
  280. typedef struct Poly_Struct POLY;
  281. typedef struct Disc_Struct DISC;
  282. typedef struct Cone_Struct CYLINDER;
  283. typedef struct Cone_Struct CONE;
  284. typedef struct Light_Source_Struct LIGHT_SOURCE;
  285. typedef struct Bicubic_Patch_Struct BICUBIC_PATCH;
  286. typedef struct Triangle_Struct TRIANGLE;
  287. typedef struct Smooth_Triangle_Struct SMOOTH_TRIANGLE;
  288. typedef struct Plane_Struct PLANE;
  289. typedef struct CSG_Struct CSG;
  290. typedef struct Box_Struct BOX;
  291. typedef struct Blob_Struct BLOB;
  292. typedef struct Ray_Struct RAY;
  293. typedef struct Frame_Struct FRAME;
  294. typedef struct istack_struct ISTACK;
  295. typedef int TOKEN;
  296. typedef int CONSTANT;
  297. typedef struct Chunk_Header_Struct CHUNK_HEADER;
  298. typedef struct Data_File_Struct DATA_FILE;
  299. typedef struct complex_block complex;
  300. typedef struct Height_Field_Struct HEIGHT_FIELD;
  301. typedef short WORD;
  302.  
  303. struct Vector_Struct
  304.   {
  305.    DBL x, y, z;
  306.   };
  307. #define Destroy_Vector(x) if ((x)!=NULL) free(x)
  308. #define Destroy_Float(x) if ((x)!=NULL) free(x)
  309.  
  310. struct Colour_Struct
  311.   {
  312.    DBL Red, Green, Blue, Filter;
  313.   };
  314.  
  315. #define Make_Colour(c,r,g,b) {(c)->Red=(r);(c)->Green=(g);(c)->Blue=(b);(c)->Filter=0.0;}
  316. #define Make_ColourA(c,r,g,b,a) {(c)->Red=(r);(c)->Green=(g);(c)->Blue=(b);(c)->Filter=(a);}
  317. #define Make_Vector(v,a,b,c) { (v)->x=(a);(v)->y=(b);(v)->z=(c); }
  318. #define Destroy_Colour(x) if ((x)!=NULL) free(x)
  319. #define MAX_COLOUR_MAP_ENTRIES 40
  320.  
  321. struct Colour_Map_Entry
  322.   {
  323.    DBL value;
  324.    COLOUR Colour;
  325.   };
  326.  
  327. struct Colour_Map_Struct
  328.   {
  329.    int Number_Of_Entries, Transparency_Flag, Users;
  330.    COLOUR_MAP_ENTRY *Colour_Map_Entries;
  331.   };
  332.  
  333. struct Transform_Struct
  334.   {
  335.    MATRIX matrix;
  336.    MATRIX inverse;
  337.   };
  338.  
  339. #define Destroy_Transform(x) if ((x)!=NULL) free(x)
  340.  
  341. /* Types for reading IFF files. */
  342. typedef struct {unsigned short Red, Green, Blue, Filter;} IMAGE_COLOUR;
  343.  
  344. struct Image_Line
  345.   {
  346.    unsigned char *red, *green, *blue;
  347.   };
  348.  
  349. typedef struct Image_Line IMAGE_LINE;
  350.  
  351. /* Legal image attributes */
  352. #define GIF_FILE   1
  353. #define POT_FILE   2
  354. #define DUMP_FILE  4
  355. #define IFF_FILE   8
  356. #define TGA_FILE  16
  357. #define GRAD_FILE 32
  358.  
  359. #define IMAGE_FILE    GIF_FILE+DUMP_FILE+IFF_FILE+GRAD_FILE+TGA_FILE
  360. #define NORMAL_FILE   GIF_FILE+DUMP_FILE+IFF_FILE+GRAD_FILE+TGA_FILE
  361. #define MATERIAL_FILE GIF_FILE+DUMP_FILE+IFF_FILE+GRAD_FILE+TGA_FILE
  362. #define HF_FILE       GIF_FILE+POT_FILE+TGA_FILE
  363.  
  364. struct Image_Struct
  365.   {
  366.    int Map_Type;
  367.    int File_Type;
  368.    int Interpolation_Type;
  369.    short Once_Flag;
  370.    short Use_Colour_Flag;
  371.    VECTOR Gradient;
  372.    DBL width, height;
  373.    int iwidth, iheight;
  374.    short Colour_Map_Size;
  375.    IMAGE_COLOUR *Colour_Map;
  376.    union 
  377.     {
  378.      IMAGE_LINE *rgb_lines;
  379.      unsigned char **map_lines;
  380.     } data;  
  381.   };
  382.  
  383. /* Texture types */
  384. #define PNF_TEXTURE     0
  385. #define TILE_TEXTURE    1
  386. #define MAT_TEXTURE     2
  387.  
  388. /* Image/Bump Map projection types */
  389. #define PLANAR_MAP      0
  390. #define SPHERICAL_MAP   1
  391. #define CYLINDRICAL_MAP 2
  392. #define PARABOLIC_MAP   3
  393. #define HYPERBOLIC_MAP  4
  394. #define TORUS_MAP       5
  395. #define PIRIFORM_MAP    6
  396. #define OLD_MAP         7
  397.  
  398. /* Bit map interpolation types */
  399. #define NO_INTERPOLATION 0
  400. #define NEAREST_NEIGHBOR 1
  401. #define BILINEAR         2
  402. #define CUBIC_SPLINE     3
  403. #define NORMALIZED_DIST  4
  404.  
  405. /* Coloration pigment list */
  406. #define NO_PIGMENT               0
  407. #define COLOUR_PIGMENT           1
  408. #define BOZO_PIGMENT             2
  409. #define MARBLE_PIGMENT           3
  410. #define WOOD_PIGMENT             4
  411. #define CHECKER_PIGMENT          5
  412. #define SPOTTED_PIGMENT          6
  413. #define AGATE_PIGMENT            7
  414. #define GRANITE_PIGMENT          8
  415. #define GRADIENT_PIGMENT         9
  416. #define IMAGE_MAP_PIGMENT       10
  417. #define PAINTED1_PIGMENT        11 
  418. #define PAINTED2_PIGMENT        12 
  419. #define PAINTED3_PIGMENT        13 
  420. #define ONION_PIGMENT           14 
  421. #define LEOPARD_PIGMENT         15 
  422. #define BRICK_PIGMENT           16
  423. #define MANDEL_PIGMENT          17
  424. #define HEXAGON_PIGMENT         18
  425. #define RADIAL_PIGMENT          19
  426.  
  427.  
  428. /* Normal perturbation (bumpy) texture list  */
  429. #define NO_NORMAL  0
  430. #define WAVES      1
  431. #define RIPPLES    2
  432. #define WRINKLES   3
  433. #define BUMPS      4
  434. #define DENTS      5
  435. #define BUMPY1     6
  436. #define BUMPY2     7
  437. #define BUMPY3     8
  438. #define BUMP_MAP   9
  439.  
  440. /* Pattern flags */
  441. #define NO_FLAGS      0
  442. #define HAS_FILTER    1
  443. #define FULL_BLOCKING 2
  444. #define HAS_TURB      4
  445. #define POST_DONE     8
  446.  
  447. #define TPATTERN_FIELDS int Type, Octaves, Flags; VECTOR Turbulence;  \
  448.   DBL omega, lambda, Frequency, Phase; IMAGE *Image; TRANSFORM *Trans;
  449.  
  450. #define INIT_TPATTERN_FIELDS(p,t) p->Type=t; p->Octaves=6; p->Image=NULL; \
  451.  p->Frequency=1.0; p->Phase=0.0;\
  452.  p->Trans=NULL; p->Flags=NO_FLAGS; p->omega=0.5;p->lambda=2.0; \
  453.  Make_Vector(&(p->Turbulence),0.0,0.0,0.0);
  454.  
  455. /* This is an abstract structure that is never actually used.
  456.    Pigment and Tnormal are descendents of this primative type */
  457.  
  458. struct Pattern_Struct
  459.   {
  460.    TPATTERN_FIELDS
  461.   };
  462.  
  463. struct Pigment_Struct
  464.   {
  465.    TPATTERN_FIELDS
  466.    COLOUR *Colour1;
  467.    COLOUR Quick_Colour;
  468.    COLOUR_MAP *Colour_Map;
  469.    VECTOR Colour_Gradient;
  470.    DBL Mortar, Agate_Turb_Scale;
  471.    int Iterations; /* mhs 10/92 for fractal textures */
  472.   };
  473.  
  474. struct Tnormal_Struct
  475.   {
  476.    TPATTERN_FIELDS
  477.    DBL Amount;
  478.   };
  479.  
  480. struct Finish_Struct
  481.   {
  482.    DBL Reflection, Ambient, Diffuse, Brilliance, Index_Of_Refraction;
  483.    DBL Refraction, Specular, Roughness, Phong, Phong_Size;
  484.    DBL Crand;
  485.    short Metallic_Flag;
  486.   };
  487.  
  488. #define Destroy_Finish(x) if ((x)!=NULL) free(x)
  489.  
  490. #define TEXTURE_FIELDS unsigned char Type,Flags; TEXTURE *Next_Material; \
  491.  TEXTURE *Next_Layer;
  492. #define TRANS_TEXTURE_FIELDS TEXTURE_FIELDS TRANSFORM *Trans;
  493.  
  494. struct Texture_Struct
  495.   {
  496.    TEXTURE_FIELDS
  497.    PIGMENT *Pigment;
  498.    TNORMAL *Tnormal;
  499.    FINISH *Finish;
  500.   };
  501.  
  502. struct Tiles_Texture_Struct
  503.   {
  504.    TRANS_TEXTURE_FIELDS
  505.    TEXTURE *Tile1;
  506.    TEXTURE *Tile2;
  507.   };
  508.  
  509. struct Material_Texture_Struct
  510.   {
  511.    TRANS_TEXTURE_FIELDS
  512.    TEXTURE *Materials;
  513.    IMAGE *Image;
  514.    int Num_Of_Mats;
  515.   };
  516.  
  517. /* Object types */
  518. #define BASIC_OBJECT            0
  519. #define PATCH_OBJECT            1   /* Has no inside, no inverse */
  520. #define TEXTURED_OBJECT         2   /* Has texture, possibly in children */
  521.  
  522. #define CHILDREN_FLAGS (PATCH_OBJECT+TEXTURED_OBJECT)
  523.                                     /* Reverse inherited flags */
  524.  
  525. #define COMPOUND_OBJECT         4   /* Has children field */
  526. #define STURM_OK_OBJECT         8   /* STRUM legal */
  527. #define WATER_LEVEL_OK_OBJECT  16   /* WATER_LEVEL legal */
  528. #define LIGHT_SOURCE_OBJECT    32   /* link me in frame.light_sources */
  529. #define BOUNDING_OBJECT        64   /* This is a holder for bounded object */
  530. #define SMOOTH_OK_OBJECT      128   /* SMOOTH legal */
  531. #define IS_CHILD_OBJECT       256   /* Object is inside a COMPOUND */
  532. #define DOUBLE_ILLUMINATE     512   /* Illuminate both sides of surface to
  533.                                        avoid normal purturb bug */
  534.  
  535. #define COMPOSITE_OBJECT       (BOUNDING_OBJECT)
  536. #define SPHERE_OBJECT          (BASIC_OBJECT)
  537. #define PLANE_OBJECT           (BASIC_OBJECT)
  538. #define QUADRIC_OBJECT         (BASIC_OBJECT)
  539. #define BOX_OBJECT             (BASIC_OBJECT)
  540. #define CONE_OBJECT            (BASIC_OBJECT)
  541. #define DISC_OBJECT            (BASIC_OBJECT)
  542. #define HEIGHT_FIELD_OBJECT    (BASIC_OBJECT+WATER_LEVEL_OK_OBJECT+SMOOTH_OK_OBJECT)
  543. #define TRIANGLE_OBJECT        (PATCH_OBJECT)
  544. #define SMOOTH_TRIANGLE_OBJECT (PATCH_OBJECT+DOUBLE_ILLUMINATE)
  545. #define BICUBIC_PATCH_OBJECT   (PATCH_OBJECT+DOUBLE_ILLUMINATE)
  546. #define UNION_OBJECT           (COMPOUND_OBJECT)
  547. #define MERGE_OBJECT           (COMPOUND_OBJECT)
  548. #define INTERSECTION_OBJECT    (COMPOUND_OBJECT)
  549. #define CUBIC_OBJECT           (STURM_OK_OBJECT)
  550. #define QUARTIC_OBJECT         (STURM_OK_OBJECT)
  551. #define POLY_OBJECT            (STURM_OK_OBJECT)
  552. #define BLOB_OBJECT            (STURM_OK_OBJECT)
  553. #define LIGHT_OBJECT           (COMPOUND_OBJECT+PATCH_OBJECT+LIGHT_SOURCE_OBJECT)
  554.  
  555. typedef int (*ALL_INTERSECTIONS_METHOD)PARAMS((OBJECT *, RAY *, ISTACK *));
  556. typedef int (*INSIDE_METHOD)PARAMS((VECTOR *, OBJECT *));
  557. typedef void (*NORMAL_METHOD)PARAMS((VECTOR *, OBJECT *, VECTOR *));
  558. typedef void *(*COPY_METHOD)PARAMS((OBJECT *));
  559. typedef void (*TRANSLATE_METHOD)PARAMS((OBJECT *, VECTOR *));
  560. typedef void (*ROTATE_METHOD)PARAMS((OBJECT *, VECTOR *));
  561. typedef void (*SCALE_METHOD)PARAMS((OBJECT *, VECTOR *));
  562. typedef void (*TRANSFORM_METHOD)PARAMS((OBJECT *, TRANSFORM *));
  563. typedef void (*INVERT_METHOD)PARAMS((OBJECT *));
  564. typedef void (*DESTROY_METHOD)PARAMS((OBJECT *));
  565.  
  566. struct Method_Struct
  567.   {
  568.    ALL_INTERSECTIONS_METHOD All_Intersections_Method;
  569.    INSIDE_METHOD Inside_Method;
  570.    NORMAL_METHOD Normal_Method;
  571.    COPY_METHOD Copy_Method;
  572.    TRANSLATE_METHOD Translate_Method;
  573.    ROTATE_METHOD Rotate_Method;
  574.    SCALE_METHOD Scale_Method;
  575.    TRANSFORM_METHOD Transform_Method;
  576.    INVERT_METHOD Invert_Method;
  577.    DESTROY_METHOD Destroy_Method;
  578.   };
  579.  
  580. #define All_Intersections(x,y,z) ((*((x)->Methods->All_Intersections_Method)) (x,y,z))
  581. #define Inside(x,y) ((*((y)->Methods->Inside_Method)) (x,y))
  582. #define Normal(x,y,z) ((*((y)->Methods->Normal_Method)) (x,y,z))
  583. #define Copy(x) ((*((x)->Methods->Copy_Method)) (x))
  584. #define Translate(x,y) ((*((x)->Methods->Translate_Method)) (x,y))
  585. #define Scale(x,y) ((*((x)->Methods->Scale_Method)) (x,y))
  586. #define Rotate(x,y) ((*((x)->Methods->Rotate_Method)) (x,y))
  587. #define Transform(x,y) ((*((x)->Methods->Transform_Method)) (x,y))
  588. #define Invert(x) ((*((x)->Methods->Invert_Method)) (x))
  589. #define Destroy(x) ((*((x)->Methods->Destroy_Method)) (x))
  590.  
  591. #define Destroy_Camera(x) if ((x)!=NULL) free(x)
  592.  
  593. struct Camera_Struct
  594.   {
  595.    VECTOR Location;
  596.    VECTOR Direction;
  597.    VECTOR Up;
  598.    VECTOR Right;
  599.    VECTOR Sky;
  600.   };
  601.  
  602. struct Bounding_Box_Struct {
  603.    VECTOR Lower_Left, Lengths;
  604.    };
  605.  
  606. /* These fields are common to all objects */
  607.  
  608. #define OBJECT_FIELDS \
  609.  METHODS *Methods;\
  610.  int Type;\
  611.  OBJECT *Sibling;\
  612.  TEXTURE *Texture;\
  613.  OBJECT *Bound;\
  614.  OBJECT *Clip;\
  615.  BBOX Bounds;\
  616.  short No_Shadow_Flag;
  617.  
  618. /* These fields are common to all compound objects */
  619. #define COMPOUND_FIELDS \
  620.  OBJECT_FIELDS \
  621.  OBJECT *Children;
  622.  
  623. #define INIT_OBJECT_FIELDS(o,t,m)\
  624.  o->Type=t;o->Methods= m;o->Sibling=NULL;o->Texture=NULL;\
  625.  o->Bound=NULL;o->Clip=NULL;o->No_Shadow_Flag=FALSE;\
  626.  Make_Vector(&o->Bounds.Lower_Left, -BOUND_HUGE/2, -BOUND_HUGE/2, -BOUND_HUGE/2)\
  627.  Make_Vector(&o->Bounds.Lengths, BOUND_HUGE, BOUND_HUGE, BOUND_HUGE)
  628.  
  629. /* This is an abstract structure that is never actually used.
  630.    All other objects are descendents of this primative type */
  631.  
  632. struct Object_Struct
  633.   {
  634.    OBJECT_FIELDS
  635.   };
  636.  
  637. struct CSG_Struct
  638.   {
  639.    COMPOUND_FIELDS
  640.   };
  641.  
  642. struct Light_Source_Struct
  643.   {
  644.    COMPOUND_FIELDS
  645.    COLOUR Colour;
  646.    VECTOR Center, Points_At, Axis1, Axis2;
  647.    DBL Coeff, Radius, Falloff;
  648.    LIGHT_SOURCE *Next_Light_Source;
  649.    unsigned char Light_Type, Area_Light, Jitter, Track;
  650.    int    Area_Size1, Area_Size2;
  651.    int    Adaptive_Level;
  652.    COLOUR **Light_Grid;
  653.    OBJECT *Shadow_Cached_Object;
  654.   };
  655.  
  656. /* Light source types */
  657. #define POINT_SOURCE     1
  658. #define SPOT_SOURCE      2
  659.  
  660. #define BUNCHING_FACTOR 4
  661. struct Composite_Struct
  662.   {
  663.    OBJECT_FIELDS
  664.    unsigned short int Entries;
  665.    OBJECT *Objects[BUNCHING_FACTOR];
  666.   };
  667.  
  668. struct Sphere_Struct
  669.   {
  670.    OBJECT_FIELDS
  671.    TRANSFORM *Trans; 
  672.    VECTOR  Center;
  673.    DBL     Radius;
  674.    DBL     Radius_Squared;
  675.    DBL     Inverse_Radius;
  676.    VECTOR  CMOtoC;
  677.    DBL     CMOCSquared;
  678.    short   CMinside, CMCached, Inverted;
  679.   };
  680.  
  681. struct Quadric_Struct
  682.   {
  683.    OBJECT_FIELDS
  684.    VECTOR  Square_Terms;
  685.    VECTOR  Mixed_Terms;
  686.    VECTOR  Terms;
  687.    DBL Constant;
  688.    DBL CM_Constant;
  689.    short Constant_Cached;
  690.    short Non_Zero_Square_Term;
  691.   };
  692.  
  693. typedef unsigned short HF_val;
  694.  
  695. typedef struct {
  696.    HF_val min_y, max_y;
  697. } HF_BLOCK;
  698.  
  699. typedef struct {
  700.         float x, z;
  701.         VECTOR normal;
  702. } Cached_Normals;
  703.  
  704. typedef short HF_Normals[3];
  705. #define HF_CACHE_SIZE 16
  706. #define LOWER_TRI 0
  707. #define UPPER_TRI 1
  708.  
  709.  
  710.  
  711. struct Height_Field_Struct
  712.   {
  713.    OBJECT_FIELDS 
  714.    TRANSFORM *Trans; 
  715.    BOX *bounding_box;
  716.    DBL Block_Size;
  717.    DBL Inv_Blk_Size;
  718.    HF_BLOCK **Block;
  719.    HF_val **Map;
  720.    int Inverted;
  721.    int cache_pos;
  722.    Cached_Normals Normal_Vector[HF_CACHE_SIZE];
  723.    int Smoothed;
  724.    HF_Normals **Normals;
  725.    };
  726.  
  727. struct Box_Struct
  728.   {
  729.    OBJECT_FIELDS 
  730.    TRANSFORM *Trans; 
  731.    VECTOR bounds[2];
  732.    short Inverted;
  733.   };
  734.  
  735. #define MAX_ORDER 15
  736.  
  737. #define STURM_FIELDS  OBJECT_FIELDS int Sturm_Flag;
  738.  
  739. /* Number of coefficients of a three variable polynomial of order x */
  740. #define term_counts(x) (((x)+1)*((x)+2)*((x)+3)/6)
  741.  
  742. struct Poly_Struct
  743.   {
  744.    STURM_FIELDS
  745.    TRANSFORM *Trans;
  746.    short Inverted;
  747.    int Order;
  748.    DBL *Coeffs;
  749.   };
  750.  
  751. struct Disc_Struct {
  752.    OBJECT_FIELDS
  753.    TRANSFORM *Trans; /* Transformation of a Disc object */
  754.    VECTOR center;    /* Center of the disc */
  755.    VECTOR normal;    /* Direction perpendicular to the disc (plane normal) */
  756.    DBL d;            /* The constant part of the plane equation */
  757.    DBL iradius2;     /* Distance from center to inner circle of the disc */
  758.    DBL oradius2;     /* Distance from center to outer circle of the disc */
  759.    short Inverted;
  760.    };
  761.  
  762. struct Cone_Struct {
  763.    OBJECT_FIELDS
  764.    TRANSFORM *Trans;   /* Transformation of a Cone object */
  765.    short int cyl_flag; /* Is this a cone or a cylinder? */
  766.    short int closed;   /* Currently unused - for making caps on the cone */
  767.    VECTOR apex;        /* Center of the top of the cone */
  768.    VECTOR base;        /* Center of the bottom of the cone */
  769.    DBL apex_radius;    /* Radius of the cone at the top */
  770.    DBL base_radius;    /* Radius of the cone at the bottom */
  771.    DBL dist;           /* Distance to end of cone in canonical coords */
  772.    short Inverted;
  773.    };
  774.  
  775. typedef struct Bezier_Node_Struct BEZIER_NODE;
  776. typedef struct Bezier_Child_Struct BEZIER_CHILDREN;
  777. typedef struct Bezier_Vertices_Struct BEZIER_VERTICES;
  778.  
  779. struct Bezier_Child_Struct
  780.   {
  781.    BEZIER_NODE *Children[4];
  782.   };
  783.  
  784. struct Bezier_Vertices_Struct
  785.   {
  786.    float uvbnds[4];
  787.    VECTOR Vertices[4];
  788.   };
  789.  
  790. struct Bezier_Node_Struct
  791.   {
  792.    int Node_Type;      /* Is this an interior node, or a leaf */
  793.    VECTOR Center;      /* Center of sphere bounding the (sub)patch */
  794.    DBL Radius_Squared; /* Radius of bounding sphere (squared) */
  795.    int Count;          /* # of subpatches associated with this node */
  796.    void *Data_Ptr;     /* Either pointer to vertices or pointer to children */
  797.   };
  798.  
  799. #define BEZIER_INTERIOR_NODE 0
  800. #define BEZIER_LEAF_NODE 1
  801.  
  802. #define MAX_PATCH_TYPE 4
  803.  
  804. struct Bicubic_Patch_Struct
  805.   {
  806.    OBJECT_FIELDS
  807.    int Patch_Type, U_Steps, V_Steps;
  808.    VECTOR Control_Points[4][4];
  809.    VECTOR Bounding_Sphere_Center;
  810.    DBL Bounding_Sphere_Radius;
  811.    DBL Flatness_Value;
  812.    BEZIER_NODE *Node_Tree;
  813.   };
  814.    
  815. #define X_AXIS 0
  816. #define Y_AXIS 1
  817. #define Z_AXIS 2
  818.  
  819. struct Triangle_Struct
  820.   {
  821.    OBJECT_FIELDS
  822.    VECTOR  Normal_Vector;
  823.    DBL     Distance;
  824.    DBL     CMNormDotOrigin;
  825.    unsigned int  CMCached:1;
  826.    unsigned int  Dominant_Axis:2;
  827.    unsigned int  vAxis:2;  /* used only for smooth triangles */
  828.    VECTOR  P1, P2, P3;
  829.    short int Degenerate_Flag;
  830.   };
  831.  
  832. struct Smooth_Triangle_Struct
  833.   {
  834.    OBJECT_FIELDS
  835.    VECTOR  Normal_Vector;
  836.    DBL     Distance;
  837.    DBL     CMNormDotOrigin;
  838.    unsigned int  CMCached:1;
  839.    unsigned int  Dominant_Axis:2;
  840.    unsigned int  vAxis:2;         /* used only for smooth triangles */
  841.    VECTOR  P1, P2, P3;
  842.    short int Degenerate_Flag;
  843.    VECTOR  N1, N2, N3, Perp;
  844.    DBL  BaseDelta;
  845.   };
  846.  
  847. struct Plane_Struct
  848.   {
  849.    OBJECT_FIELDS
  850.    VECTOR  Normal_Vector;
  851.    DBL     Distance;
  852.    DBL     CMNormDotOrigin;
  853.    int     CMCached;
  854.   };
  855.  
  856. typedef struct {
  857.    VECTOR pos;
  858.    DBL radius2;
  859.    DBL coeffs[3];
  860.    DBL tcoeffs[5];
  861.    } Blob_Element;
  862.  
  863. typedef struct blob_list_struct *blobstackptr;
  864. struct blob_list_struct {
  865.    Blob_Element elem;
  866.    blobstackptr next;
  867.    };
  868.  
  869. typedef struct {
  870.    int type, index;
  871.    DBL bound;
  872.    } Blob_Interval;
  873.  
  874. struct Blob_Struct
  875.    {
  876.    STURM_FIELDS
  877.    TRANSFORM *Trans;
  878.    short Inverted;
  879.    int count;
  880.    DBL threshold;
  881.    Blob_Element **list;
  882.    Blob_Interval *intervals;
  883. };
  884.  
  885. #define MAX_CONTAINING_OBJECTS 10
  886.  
  887. struct Ray_Struct
  888.   {
  889.    VECTOR Initial;               /*  Xo  Yo  Zo  */
  890.    VECTOR Direction;             /*  Xv  Yv  Zv  */
  891.    VECTOR Initial_2;             /*  Xo^2  Yo^2  Zo^2  */
  892.    VECTOR Direction_2;           /*  Xv^2  Yv^2  Zv^2  */
  893.    VECTOR Initial_Direction;     /*  XoXv  YoYv  ZoZv  */
  894.    VECTOR Mixed_Initial_Initial; /*  XoYo  XoZo  YoZo  */
  895.    VECTOR Mixed_Dir_Dir;         /*  XvYv  XvZv  YvZv  */
  896.    VECTOR Mixed_Init_Dir;        /*  XoYv+XvYo  XoZv+XvZo  YoZv+YvZo  */
  897.    int Containing_Index;
  898.    TEXTURE *Containing_Textures [MAX_CONTAINING_OBJECTS];
  899.    DBL Containing_IORs [MAX_CONTAINING_OBJECTS];
  900.    int Quadric_Constants_Cached;
  901.   };
  902.  
  903. struct Frame_Struct
  904.   {
  905.    CAMERA *Camera;
  906.    int Screen_Height, Screen_Width;
  907.    LIGHT_SOURCE *Light_Sources;
  908.    OBJECT *Objects;
  909.    DBL Atmosphere_IOR, Antialias_Threshold;
  910.    DBL Fog_Distance;
  911.    COLOUR Fog_Colour;
  912.    COLOUR Background_Colour;
  913.   };
  914.  
  915. #define DISPLAY 1
  916. #define VERBOSE 2
  917. #define DISKWRITE 4
  918. #define PROMPTEXIT 8
  919. #define ANTIALIAS 16
  920. #define DEBUGGING 32
  921. #define RGBSEPARATE 64
  922. #define EXITENABLE 128
  923. #define CONTINUE_TRACE 256
  924. #define VERBOSE_FILE 512
  925. #define JITTER 1024
  926.  
  927. /* Definitions for ISTACK structure */
  928.  
  929. struct istk_entry
  930.   {
  931.    DBL Depth;
  932.    VECTOR IPoint;
  933.    VECTOR INormal;
  934.    int NFlag;
  935.    OBJECT *Object;
  936.   };
  937.  
  938. struct istack_struct
  939.   {
  940.    struct istack_struct *next;
  941.    struct istk_entry *istack;
  942.    unsigned int top_entry;
  943.   };
  944.  
  945. #define itop(i) i->istack[i->top_entry]
  946. #define push_entry(d,v,o,i) itop(i).Depth=d; itop(i).IPoint=v; \
  947.  itop(i).NFlag=0; itop(i).Object=o; incstack(i);
  948. #define push_normal_entry(d,v,n,o,i) itop(i).Depth=d; itop(i).IPoint=v; \
  949.  itop(i).INormal=n; itop(i).NFlag=1; itop(i).Object=o; incstack(i);
  950. #define push_copy(i,e) itop(i)= *e; incstack(i);
  951. #define pop_entry(i) (i->top_entry > 0)?&(i->istack[--i->top_entry]):NULL
  952.  
  953. #define MAX_STRING_INDEX 41 
  954.  
  955. struct Reserved_Word_Struct
  956.   {
  957.    TOKEN Token_Number;
  958.    char *Token_Name;
  959.   };
  960.  
  961. /* Here's where you dump the information on the current token (fm. PARSE.C) */
  962.  
  963. struct Token_Struct
  964.   {
  965.    TOKEN Token_Id;
  966.    int Token_Line_No;
  967.    char *Token_String;
  968.    DBL Token_Float;
  969.    TOKEN Begin_Id;
  970.    int Constant_Index;
  971.    int Unget_Token, End_Of_File;
  972.    char *Filename, *Constant_Data;
  973.   };
  974.  
  975. /* Types of constants allowed in DECLARE statement (fm. PARSE.C) */
  976.  
  977. #define COLOUR_CONSTANT         0
  978. #define VECTOR_CONSTANT         1
  979. #define FLOAT_CONSTANT          2
  980. #define PIGMENT_CONSTANT        3
  981. #define TNORMAL_CONSTANT        4
  982. #define FINISH_CONSTANT         5
  983. #define TEXTURE_CONSTANT        6
  984. #define OBJECT_CONSTANT         7
  985. #define COLOUR_MAP_CONSTANT     8
  986. #define TRANSFORM_CONSTANT      9
  987. #define CAMERA_CONSTANT        10
  988.  
  989. /* CSG types */
  990. #define CSG_UNION_TYPE             1
  991. #define CSG_INTERSECTION_TYPE      2
  992. #define CSG_DIFFERENCE_TYPE        4
  993. #define CSG_MERGE_TYPE             8
  994. #define CSG_SINGLE_TYPE           16
  995.  
  996. struct Constant_Struct
  997.   {
  998.    int Identifier_Number;
  999.    CONSTANT Constant_Type;
  1000.    char *Constant_Data;
  1001.   };
  1002.  
  1003. struct Chunk_Header_Struct 
  1004.   {
  1005.    long name;
  1006.    long size;
  1007.   };
  1008.  
  1009. struct Data_File_Struct 
  1010.   {
  1011.    FILE *File;
  1012.    char *Filename;
  1013.    int Line_Number;
  1014.   };
  1015.  
  1016. struct complex_block 
  1017.   {
  1018.    DBL r, c;
  1019.   };
  1020.  
  1021. #define READ_MODE 0
  1022. #define WRITE_MODE 1
  1023. #define APPEND_MODE 2
  1024.  
  1025. struct file_handle_struct 
  1026.   {
  1027.    char *filename;
  1028.    int  mode;
  1029.    int width, height;
  1030.    int buffer_size;
  1031.    char *buffer;
  1032.    FILE *file;
  1033.    char *(*Default_File_Name_p) PARAMS((void));
  1034.    int  (*Open_File_p) PARAMS((struct file_handle_struct *handle,
  1035.            char *name, int *width, int *height, int buffer_size,
  1036.            int mode));
  1037.    void (*Write_Line_p) PARAMS((struct file_handle_struct *handle,
  1038.            COLOUR *line_data, int line_number));
  1039.    int  (*Read_Line_p) PARAMS((struct file_handle_struct *handle,
  1040.            COLOUR *line_data, int *line_number));
  1041.    void (*Read_Image_p) PARAMS((IMAGE *Image, char *filename));
  1042.    void (*Close_File_p) PARAMS((struct file_handle_struct *handle));
  1043.   };
  1044.  
  1045. typedef struct file_handle_struct FILE_HANDLE;
  1046.  
  1047. #define Default_File_Name(h) ((*((h)->Default_File_Name_p)) ())
  1048. #define Open_File(h,n,wd,ht,sz,m) ((*((h)->Open_File_p)) (h,n,wd,ht,sz,m))
  1049. #define Write_Line(h,l,n) ((*((h)->Write_Line_p)) (h, l, n))
  1050. #define Read_Line(h,l,n) ((*((h)->Read_Line_p)) (h, l, n))
  1051. #define Read_Image(h,i) ((*((h)->Read_Image_p)) (h, i))
  1052. #define Close_File(h) ((*((h)->Close_File_p)) (h))
  1053.  
  1054.  
  1055. #define Q_FULL_AMBIENT 1
  1056. #define Q_QUICKC       2
  1057. #define Q_SHADOW       4
  1058. #define Q_AREA_LIGHT   8
  1059. #define Q_REFRACT     16
  1060. #define Q_REFLECT     32
  1061. #define Q_NORMAL      64
  1062.  
  1063. #define QUALITY_0 Q_QUICKC+Q_FULL_AMBIENT
  1064. #define QUALITY_1 QUALITY_0
  1065. #define QUALITY_2 QUALITY_1-Q_FULL_AMBIENT
  1066. #define QUALITY_3 QUALITY_2
  1067. #define QUALITY_4 QUALITY_3+Q_SHADOW
  1068. #define QUALITY_5 QUALITY_4+Q_AREA_LIGHT
  1069. #define QUALITY_6 QUALITY_5-Q_QUICKC+Q_REFRACT
  1070. #define QUALITY_7 QUALITY_6
  1071. #define QUALITY_8 QUALITY_7+Q_REFLECT+Q_NORMAL
  1072. #define QUALITY_9 QUALITY_8
  1073.